package Binrary_Management_System.ioPeration;

import Binrary_Management_System.Book.Book;
import Binrary_Management_System.Book.BookList;

import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 何华树
 * Date: 2024-09-13
 * Time: 14:04
 */
public class DelOperation implements IOperation{
    @Override
    public void work(BookList bookList) {
        System.out.println("删除图书！");

        int currentSize = bookList.getUseSize();

        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入你要删除的图书的书名：");
        String name = scanner.nextLine();
        int i = 0;
        for (i = 0; i < currentSize; i++) {
            if(bookList.getBook(i).getName().equals(name)) {
                for (int j = i; j < currentSize-1; j++) {
                    Book book = bookList.getBook(j+1);
                    bookList.setBook(j,book);
                }
                bookList.setBook(currentSize,null);
                bookList.setUseSize(currentSize-1);
                System.out.println("删除成功！");
                return;
            }
        }
        if(i == currentSize) {
            System.out.println("没有你要删除的图书！");
        }
    }
}
